#登录业务类

import allure
#导入和该业务有关的页面类
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

class ServiceLogin(object):
    def __init__(self,driver,base_url):
        #初始化和该业务有关的页面对象
        self.page_index=PageIndex(driver,base_url)
        self.page_login=PageLogin(driver,base_url)
        self.page_user=PageUser(driver,base_url)


    def service_login_001(self,d):
        #完成首页页面中的UI步骤
        allure.attach("","步骤1：打开首页")
        self.page_index.openUrl()
        allure.attach("", "步骤2：点击首页上的登录按钮")
        self.page_index.click_loginButton()

        #完成登录页中的UI步骤
        allure.attach("", f"步骤3：在登录页面中输入账号{d['zanhao']}")
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()

        #完成个人中心页面中的UI步骤
        imgName=self.page_user.savePng("登录业务",d["key"]) ##"登录_K001_20250402110315.png"

        allure.attach(open(f'./screen/{imgName}', 'rb').read(), "本次截图",allure.attachment_type.PNG)

        siji=self.page_user.getNicenH2Text() #"nswe，欢迎光临"
        yuqi=d["yuqi"]
        return siji==yuqi

    def service_login_002(self,d):
        #完成首页页面中的UI步骤
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页中的UI步骤
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()
        siji=self.page_login.getErrorTipDivText() #“账号或密码错误"
        yuqi=d["yuqi"] #"错误"
        return yuqi in siji


    def service_login_003(self,d):
        #完成首页页面中的UI步骤
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页中的UI步骤
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()
        siji=self.page_login.getZanhaoClassAttr() #"input_text      invalid-text"
        yuqi=d["yuqi"]
        return yuqi in siji



    def service_login_004(self,d):
        #完成首页页面中的UI步骤
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页中的UI步骤
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()

        #完成个人中心页面中的UI步骤
        siji=self.page_login.getPwdClassAttr() #"input_text  valid-text invalid-text"
        yuqi=d["yuqi"]
        return yuqi in siji
